package dyyx;

import java.util.SortedMap;
import java.util.TreeMap;

public class TreeMapTest {
	
	public static void main(String[] args) throws Exception {
		
		System.out.println("hello,TreeMapTest");
		SortedMap<Integer,String> map = new TreeMap<Integer,String>();
		
		int num = 10;
		for(int i=0;i<num;i++){
			map.put(i, "value"+i);
		}
		
		System.out.println(map);
		
		// tailMap(K fromKey)  大于等于 fromKey
		SortedMap<Integer,String> tailMap = map.tailMap(7);
		// {7=value7, 8=value8, 9=value9}
		System.out.println(tailMap);
		
		// 7 
		System.out.println(tailMap.firstKey());
		// 9
		System.out.println(tailMap.lastKey());

		//  headMap(K toKey)  小于 toKey
		SortedMap<Integer,String> headMap = map.headMap(7);
		// {0=value0, 1=value1, 2=value2, 3=value3, 4=value4, 5=value5, 6=value6}
		System.out.println(headMap);
		// 0
		System.out.println(headMap.firstKey());
		
		// subMap(K fromKey, K toKey)   大于等于 fromKey 小于 toKey
		SortedMap<Integer,String> subMap = map.subMap(3, 5);	
		// {3=value3, 4=value4}
		System.out.println(subMap);

	}
}
